package com.bilibili.ifelse;

import java.util.Scanner;

//制作一个简易版的斗地主游戏
public class try0 {
    public static void main(String[] args) {
        String arr[] = new String[54];
        reset(arr);
        comeon(arr);
    }

    public static void comeon(String arr[]) {
        boolean a = true ;
        Scanner come = new Scanner(System.in);
        while (a) {
            System.out.println("目录：");
            System.out.println("1.洗牌");
            System.out.println("2.发牌");
            System.out.println("3.复位卡牌");
            System.out.println("4.退出");
            System.out.println("请输入：");
            int num = come.nextInt();
            switch (num) {
                case 1:
                    shuffle(arr);
                    break;
                case 2:
                    deal(arr);
                    break;
                case 3:
                    reset(arr);
                    break;
                case 4:
                    a=false;
                    break;
                default:
                    System.out.println("请重新输入！");
            }
        }
    }
    public static String[] reset(String arr[]){
        for (int i = 0; i < arr.length; i++) {
            arr[i] = null;
        }
        String arrnum[]= {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
        String arrcolors[] = {"♥","♠","♦","♣"};
        //Scanner cards = new Scanner(System.in);
        System.out.println("---------------------------------------------------------------------------------------");
        System.out.println("---------------------------------------------------------------------------------------");
        int work = 0 ;
        for(int i = 0; i<arrcolors.length ; i++){
            for (int j = 0 ; j < arrnum.length ; j++ ) {
                arr[work]=arrcolors[i]+arrnum[j];
                work++;
            }
        }
        arr[52]="小王";
        arr[53]="大王";
        for(int i =0;i<arr.length;i++){
            System.out.print(" "+arr[i]);
            if(i==51||i==25||i==12||i==38){
                System.out.println();
            }
        }
        System.out.println();
        System.out.println("---------------------------------------------------------------------------------------");
        System.out.println("---------------------------------------------------------------------------------------");
        return arr;
    }
    public static void shuffle(String arr[]){
        for (int i = 0; i < 54; i++) {
            int num1 = (int)(Math.random()*54);
            int num2 = (int)(Math.random()*54);
            String card = arr[num1];
            arr[num1]=arr[num2];
            arr[num2]=card;
        }
        System.out.println("---------------------------------------------------------------------------------------");
        System.out.println("---------------------------------------------------------------------------------------");
        for (int i = 0; i < 54; i++){
            System.out.print("\t"+arr[i]);
        }
        System.out.println();
        System.out.println("---------------------------------------------------------------------------------------");
        System.out.println("---------------------------------------------------------------------------------------");
    }
    public static void deal(String arr[]){
        System.out.println("---------------------------------------------------------------------------------------");
        System.out.println("---------------------------------------------------------------------------------------");
        System.out.println("玩家1：");
        for (int i = 0 ; i < 17 ; i++){
            System.out.print("\t"+arr[3*i]);
        }
        System.out.println();
        System.out.println("玩家2：");
        for (int i = 0 ; i < 17 ; i++){
            System.out.print("\t"+arr[3*i+1]);
        }
        System.out.println();
        System.out.println("玩家3：");
        for (int i = 0 ; i < 17 ; i++){
            System.out.print("\t"+arr[3*i+2]);
        }
        System.out.println();
        System.out.println("地主牌：");
        for (int i = 51 ; i < 54 ; i++){
            System.out.print("\t"+arr[i]);
        }
        System.out.println();
        System.out.println("---------------------------------------------------------------------------------------");
        System.out.println("---------------------------------------------------------------------------------------");
    }
}